Summary

Row

confirmed

3,597,168

active

3,323,777 (92.4%)

recovered

NA (NA%)

death

273,391 (7.6%)

Row

confirmed

230,087,742

active

225,368,564 (97.9%)

recovered

0 (0%)

death

4,719,178 (2.1%)

Row

Cases Distribution by Type (Countries around Mexico)

Row

Daily Cumulative Cases by Type

Recovery and Death Rates by Country

Map

Map

Data

About

The Coronavirus Dashboard

Based in the project of RamiKrispin centered in Mexico by Ricardo

This Coronavirus dashboard provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic. This dashboard is built with R using the Rmakrdown framework and can easily reproduce by others. The code behind the dashboard available here

Data

The input data for this dashboard is the coronavirus R package (dev version). The data and dashboard is refreshed on a daily bases. The raw data pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository

Packages

Deployment and reproducibly

The dashboard was deployed to Github docs. If you wish to deploy and/or modify the dashboard on your Github account, you can apply the following steps:

For any question or feedback, you can either open an issue or contact me on Twitter.

Contribution

The Map tab was contributed by Art Steinmetz on this pull request. Thanks Art!

---
title: "Coronavirus Mexico Status"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
    vertical_layout: fill
---

```{r setup, include=FALSE}
##------------------ Packages ------------------
r=getOption("repos")
r["CRAN"] = "https://cran.itam.mx"
options(repos = r)
rm(r)
if(!require(flexdashboard)) { install.packages('flexdashboard') ; require('flexdashboard') ; }
if(!require('coronavirus')) {devtools::install_github("covid19r/coronavirus");require('coronavirus')}
if ( !require('covid19italy') ) { install.packages('covid19italy') ; require('covid19italy') ; }

coronavirus = read.csv2('./data/coronavirus_dataset.csv'
                      , sep=',',stringsAsFactors = F, header = T)
coronavirus=transform(coronavirus
                    , province = as.character(province)
                    , country = as.character(country)
                    , lat = as.numeric(as.character(lat))
                    , long = as.numeric(as.character(long))
                    , date = as.Date(date, origin = "1970-01-01")
                    , type = as.character(type)
                      )

`%>%` <- magrittr::`%>%`
##------------------ Parameters ------------------
## Set colors
## https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"
##------------------ Data ------------------
df <- coronavirus %>% 
  # dplyr::filter(date == max(date)) %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total = sum(cases)) %>%
  tidyr::pivot_wider(names_from =  type, 
                     values_from = total) %>%
  dplyr::mutate(unrecovered = confirmed - ifelse(is.na(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
  dplyr::arrange(-confirmed) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(country = dplyr::if_else(country == "United Arab Emirates", "UAE", country)) %>%
  dplyr::mutate(country = dplyr::if_else(country == "Mainland China", "China", country)) %>%
  dplyr::mutate(country = dplyr::if_else(country == "North Macedonia", "N.Macedonia", country)) %>%
  dplyr::mutate(country = trimws(country)) %>%
  dplyr::mutate(country = factor(country, levels = country))

df_daily <- coronavirus %>% 
  dplyr::group_by(date, type) %>%
  dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
  tidyr::pivot_wider(names_from = type,
                     values_from = total) %>%
  dplyr::arrange(date) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(active =  confirmed - death - recovered) %>%
  dplyr::mutate(confirmed_cum = cumsum(confirmed),
                death_cum = cumsum(death),
                recovered_cum = cumsum(recovered),
                active_cum = cumsum(active))
  

df1 <- coronavirus %>% dplyr::filter(date == max(date))


##------------trajectory plot data prep------------

df_ecuador <- coronavirus %>% dplyr::filter(type == "confirmed", country == "Ecuador") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(ecuador = cumsum(cases)) %>%
  dplyr::filter(ecuador > 100)  %>%
  dplyr::select(-cases, -date)
df_ecuador$index <- 1:nrow(df_ecuador)


df_uk <- coronavirus %>% dplyr::filter(type == "confirmed", country == "United Kingdom") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(uk = cumsum(cases)) %>%
  dplyr::filter(uk > 100)  %>%
  dplyr::select(-cases, -date)
df_uk$index <- 1:nrow(df_uk)


df_fr <- coronavirus %>% dplyr::filter(type == "confirmed", country == "France") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(france = cumsum(cases)) %>%
  dplyr::filter(france > 100)  %>%
  dplyr::select(-cases, -date)
df_fr$index <- 1:nrow(df_fr)

df_us <- coronavirus %>% dplyr::filter(type == "confirmed", country == "US") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(us = cumsum(cases)) %>%
  dplyr::filter(us > 100)  %>%
  dplyr::select(-cases, -date)
df_us$index <- 1:nrow(df_us)

df_nicaragua <- coronavirus %>% dplyr::filter(type == "confirmed", country == "Nicaragua") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(nicaragua = cumsum(cases)) %>%
##  dplyr::filter(nicaragua > 100)  %>%
  dplyr::select(-cases, -date)
df_nicaragua$index <- 1:nrow(df_nicaragua)

df_canada <- coronavirus %>% dplyr::filter(type == "confirmed", country == "Canada") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(canada = cumsum(cases)) %>%
  dplyr::filter(canada > 100)  %>%
  dplyr::select(-cases, -date)
df_canada$index <- 1:nrow(df_canada)

df_mexico <- coronavirus %>% dplyr::filter(type == "confirmed", country == "Mexico") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(mexico = cumsum(cases)) %>%
  dplyr::filter(mexico > 100)  %>%
  dplyr::select(-cases, -date)
df_mexico$index <- 1:nrow(df_mexico)

df_spain <- coronavirus %>% dplyr::filter(type == "confirmed", country == "Spain") %>%
  dplyr::group_by(date) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::ungroup() %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(spain = cumsum(cases)) %>%
  dplyr::filter(spain > 100)  %>%
  dplyr::select(-cases, -date)
df_spain$index <- 1:nrow(df_spain)

df_italy <- italy_total %>% dplyr::select(date, italy = cumulative_cases) %>%
  dplyr::filter(italy > 100) %>%
  dplyr::select(-date)
df_italy$index <- 1:nrow(df_italy)

df_trajectory <- df_mexico %>%
    dplyr::left_join(df_ecuador, by = "index") %>% 
    dplyr::left_join(df_italy, by = "index") %>%
    dplyr::left_join(df_nicaragua, by = "index") %>%
    dplyr::left_join(df_canada, by = "index") %>%
    dplyr::left_join(df_us, by = "index") %>%
    dplyr::left_join(df_fr, by = "index") %>%
    dplyr::left_join(df_uk, by = "index") %>%
    dplyr::left_join(df_spain, by = "index")
```

Summary
=======================================================================
Row
-----------------------------------------------------------------------

### confirmed {.value-box}

```{r}
confirmed_mex = as.numeric(df [ df$country=='Mexico', 'confirmed'])
valueBox(value = format(confirmed_mex, big.mark = ","), 
         caption = "Mexico Confirmed Cases", 
         icon = "fas fa-user-md", 
         color = confirmed_color)
```


### active {.value-box}

```{r}
active_mex = as.numeric(df [ df$country=='Mexico', 'unrecovered'])
valueBox(value = paste(format(active_mex, big.mark = ","), " (", 
                       round(100 * active_mex / confirmed_mex, 1),
                       "%)", sep = ""), 
         caption = "Mexico Active Cases", icon = "fas fa-ambulance", 
         color = active_color)
```

### recovered {.value-box}

```{r}
recovered_mex = as.numeric(df [ df$country=='Mexico', 'recovered'])
valueBox(value = paste(format(recovered_mex, big.mark = ","), " (", 
                       round(100 * recovered_mex / confirmed_mex, 1),
                       "%)", sep = "")
        ,caption = "Mexico Recovered Cases"
       , icon = "fas fa-heartbeat"
       ,color = recovered_color)
```

### death {.value-box}

```{r}
death_mex = as.numeric(df [ df$country=='Mexico', 'death'])
valueBox(value = paste(format(death_mex, big.mark = ","), " (", 
                       round(100 * death_mex / confirmed_mex, 1),
                       "%)", sep = ""),
         caption = "Mexico Death Cases"
       , icon = "fas fa-dizzy"
        ,color = death_color)
```


Row
-----------------------------------------------------------------------

### confirmed {.value-box}

```{r}

valueBox(value = paste(format(sum(df$confirmed), big.mark = ","), "", sep = " "), 
         caption = "Total Confirmed Cases", 
         icon = "fas fa-user-md", 
         color = confirmed_color)
```


### active {.value-box}

```{r}
valueBox(value = paste(format(sum(df$unrecovered, na.rm = TRUE), big.mark = ","), " (",
                       round(100 * sum(df$unrecovered, na.rm = TRUE) / sum(df$confirmed), 1), 
                       "%)", sep = ""), 
         caption = "Active Cases", icon = "fas fa-ambulance", 
         color = active_color)
```

### recovered {.value-box}

```{r}
valueBox(value = paste(format(sum(df$recovered, na.rm = TRUE), big.mark = ","), " (",
                       round(100 * sum(df$recovered, na.rm = TRUE) / sum(df$confirmed), 1), 
                       "%)", sep = ""), 
         caption = "Recovered Cases", icon = "fas fa-heartbeat", 
         color = recovered_color)
```

### death {.value-box}

```{r}

valueBox(value = paste(format(sum(df$death, na.rm = TRUE), big.mark = ","), " (",
                       round(100 * sum(df$death, na.rm = TRUE) / sum(df$confirmed), 1), 
                       "%)", sep = ""),
         caption = "Death Cases", 
         icon = "fas fa-dizzy", 
         color = death_color)
```


Row
-----------------------------------------------------------------------

### Cases Distribution by Type (Countries around Mexico)

```{r daily_summary}

delta = 1500
mex_confirmed = as.numeric(df [ df$country == 'Mexico', 'confirmed'])
data = df [ mex_confirmed-delta < df$confirmed & df$confirmed < mex_confirmed+delta, ]
plotly::plot_ly(data = data, 
                x = ~ country, 
                y = ~ unrecovered, 
                                        # text =  ~ confirmed, 
                                        # textposition = 'auto',
                type = "bar", 
                name = "Active",
                marker = list(color = active_color)) %>%
    plotly::add_trace(y = ~ recovered, 
                                        # text =  ~ recovered, 
                                        # textposition = 'auto',
                      name = "Recovered",
                      marker = list(color = recovered_color)) %>%
    plotly::add_trace(y = ~ death, 
                                        # text =  ~ death, 
                                        # textposition = 'auto',
                      name = "Death",
                      marker = list(color = death_color)) %>%
    plotly::layout(barmode = 'stack',
                   yaxis = list(title = "Total Cases (log scaled)",
                                type = "log"),
                   xaxis = list(title = ""),
                   hovermode = "compare",
                   margin =  list(
                                        # l = 60,
                                        # r = 40,
                       b = 10,
                       t = 10,
                       pad = 2
                   ))
```

Row {data-width=400}
-----------------------------------------------------------------------


### Daily Cumulative Cases by Type
    
```{r daily_cumulative_cases_by_type}
plotly::plot_ly(data = df_daily,
                x = ~ date,
                y = ~ active_cum, 
                name = 'Active', 
                fillcolor = active_color,
                type = 'scatter',
                mode = 'none', 
                stackgroup = 'one') %>%
    plotly::add_trace(y = ~ recovered_cum,
                      name = "Recovered",
                      fillcolor = recovered_color) %>%
    plotly::add_trace(y = ~ death_cum,
                      name = "Death",
                      fillcolor = death_color) %>%
    plotly::layout(title = "",
                   yaxis = list(title = "Cumulative Number of Cases"),
                   xaxis = list(title = "Date"),
                   legend = list(x = 0.1, y = 0.9),
                   hovermode = "compare")
```


### Recovery and Death Rates by Country
    
```{r recovery_and_death_rates_by_country}
df_summary <-coronavirus %>% 
  # dplyr::filter(country != "Others") %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total_cases = sum(cases)) %>%
  tidyr::pivot_wider(names_from = type, values_from = total_cases) %>%
  dplyr::arrange(- confirmed) %>%
  dplyr::filter(confirmed >= 25) %>%
  dplyr::select(country = country, confirmed, recovered, death) %>%
  dplyr::mutate(recover_rate = recovered / confirmed,
         death_rate = death / confirmed)  
df_summary %>%
  DT::datatable(rownames = FALSE,
            colnames = c("Country", "Confirmed", "Recovered", "Death", "Recovery Rate", "Death Rate"),
            options = list(pageLength = nrow(df_summary), dom = 'tip')) %>%
  DT::formatPercentage("recover_rate", 2) %>%
  DT::formatPercentage("death_rate", 2) 
```


Map
=======================================================================

**Map**

```{r map}
# map tab added by Art Steinmetz
library(leaflet)
library(leafpop)
library(purrr)
cv_data_for_plot <- coronavirus %>% 
  dplyr::filter(cases > 0) %>% 
  dplyr::group_by(country,province,lat,long,type) %>% 
  dplyr::summarise(cases = sum(cases)) %>% 
  dplyr::mutate(log_cases = 2 * log(cases)) %>% 
  dplyr::ungroup()
cv_data_for_plot.split <- cv_data_for_plot %>% split(cv_data_for_plot$type)
pal <- colorFactor(c("orange", "red","green"), domain = c("confirmed", "death","recovered"))
map_object <- leaflet() %>% addProviderTiles(providers$Stamen.Toner)
names(cv_data_for_plot.split) %>%
  purrr::walk( function(df) {
    map_object <<- map_object %>%
      addCircleMarkers(data=cv_data_for_plot.split[[df]],
                 lng=~long, lat=~lat,
#                 label=~as.character(cases),
                 color = ~pal(type),
                 stroke = FALSE,
                 fillOpacity = 0.8,
                 radius = ~log_cases,
                 popup =  leafpop::popupTable(cv_data_for_plot.split[[df]],
                                              feature.id = FALSE,
                                              row.numbers = FALSE,
                                              zcol=c("type","cases","country","province")),
                 group = df,
#                 clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
                 labelOptions = labelOptions(noHide = F,
                                             direction = 'auto'))
  })
map_object %>%
  addLayersControl(
    overlayGroups = names(cv_data_for_plot.split),
    options = layersControlOptions(collapsed = FALSE) 
  )
```

Trends
=======================================================================

Column {data-width=400}
-------------------------------------
    
### New Cases - Countries around Mexico (`r  max(coronavirus$date)`)
    
```{r trends}
max_date <- max(coronavirus$date)
data = coronavirus %>%
    dplyr::filter(type == "confirmed", date == max_date) %>%
    dplyr::group_by(country) %>%
    dplyr::summarise(total_cases = sum(cases)) %>%
    dplyr::arrange(-total_cases) %>%
    dplyr::mutate(country = factor(country, levels = country)) %>%
    dplyr::ungroup()
delta = 100
mex_confirmed = as.numeric(data [ data$country == 'Mexico', 'total_cases'])
data %>%
    dplyr::filter(mex_confirmed - delta < total_cases ,
                  total_cases < mex_confirmed + delta) %>%
    plotly::plot_ly(x = ~ country,
                    y = ~ total_cases,
                    text = ~ total_cases,
                    textposition = 'auto',
                    type = "bar") %>%
    plotly::layout(yaxis = list(title = "Number of Cases"),
                   xaxis = list(title = ""),
                   margin =  list(
                       l = 10,
                       r = 10,
                       b = 10,
                       t = 10,
                       pad = 2
                   ))
```


### Trajectory Plot - Major Countries 

```{r trajectory_plot}
plotly::plot_ly(data = df_trajectory) %>%
    plotly::add_lines(x = ~ index,
                      y = ~ mexico,
                      name = "Mexico") %>%
    plotly::add_lines(x = ~ index,
                      y = ~ ecuador,
                      name = "Ecuador",  line = list(width = 2)) %>%
    plotly::add_lines(x = ~ index,
                      y = ~ italy,
                      line = list(color = "red", width = 2),
                      name = "Italy") %>%
    plotly::add_lines(x = ~ index,
                      y = ~ us,
                      name = "United States",  line = list(width = 2)) %>%
    plotly::add_lines(x = ~ index,
                      y = ~ uk,
                      name = "United Kingdom",  line = list(width = 2)) %>%
    plotly::add_lines(x = ~ index,
                      y = ~ france,
                      name = "France",  line = list(width = 2)) %>%
    plotly::add_lines(x = ~ index,
                      y = ~ nicaragua,
                      name = "Nicaragua",  line = list(color = "orange", width = 2)) %>%
    plotly::add_lines(x = ~ index,
                      y = ~ canada,
                      name = "Canada",  line = list(width = 2)) %>%
    plotly::add_lines(x = ~ index,
                      y = ~ spain,
                      name = "Spain") %>%
    plotly::layout(yaxis = list(title = "Cumulative Positive Cases",type = "log"),
                   xaxis = list(title = "Days since the total positive cases surpass 100"),
                   legend = list(x = 0.7, y = 0.3),
                   hovermode = "compare")
```
   
Column {data-width=600}
-------------------------------------
   
### Recovery and Death Rates for Countries total cases similar to Mexico

```{r Recovery_and Death Rates for Countries total cases similar to Mexico} 
data = coronavirus %>%
    ## dplyr::filter(country != "Others") %>%
    dplyr::group_by(country, type) %>%
    dplyr::summarise(total_cases = sum(cases)) %>%
    tidyr::pivot_wider(names_from = type, values_from = total_cases) %>%
    dplyr::arrange(- confirmed)
delta = 1000
mex_confirmed = as.numeric(data [ data$country == 'Mexico','confirmed'])

data %>%
    dplyr::filter(mex_confirmed - delta < confirmed
                , confirmed < mex_confirmed + delta) %>%
    dplyr::mutate(recover_rate = recovered / confirmed,
                  death_rate = death / confirmed) %>%
    dplyr::mutate(recover_rate = dplyr::if_else(is.na(recover_rate), 0, recover_rate),
                  death_rate = dplyr::if_else(is.na(death_rate), 0, death_rate)) %>%
    dplyr::ungroup() %>%
    dplyr::mutate(confirmed_normal = as.numeric(confirmed) / max(as.numeric(confirmed))) %>%
    plotly::plot_ly(y = ~ round(100 * recover_rate, 1),
                    x = ~ round(100 * death_rate, 1),
                    size = ~  log(confirmed),
                    sizes = c(15, 40),
                    type = 'scatter', mode = 'markers',
                    color = ~ country,
                    marker = list(sizemode = 'diameter' , opacity = 0.5),
                    hoverinfo = 'text',
                    text = ~paste("
", country, "
Confirmed Cases: ", confirmed, "
Recovery Rate: ", paste(round(100 * recover_rate, 1), "%", sep = ""), "
Death Rate: ", paste(round(100 * death_rate, 1), "%", sep = "")) ) %>% plotly::layout(yaxis = list(title = "Recovery Rate", ticksuffix = "%"), xaxis = list(title = "Death Rate", ticksuffix = "%", dtick = 1, tick0 = 0), hovermode = "compare") ``` ### Cases Status Update for `r max(coronavirus$date)` ```{r cases_status_update} daily_summary <- coronavirus %>% dplyr::filter(date == max(date)) %>% dplyr::group_by(country, type) %>% dplyr::summarise(total = sum(cases)) %>% tidyr::pivot_wider(names_from = type, values_from = total) %>% dplyr::arrange(-confirmed) %>% dplyr::select(country = country, confirmed, recovered, death) DT::datatable(data = daily_summary, rownames = FALSE, colnames = c("Country", "Confirmed", "Recovered", "Death"), options = list(pageLength = nrow(daily_summary), dom = 'tip')) ``` Data ======================================================================= ```{r data} coronavirus %>% dplyr::select(Date = date, Province = province, Country = country, `Case Type` = type, `Number of Cases` = cases) %>% DT::datatable(rownames = FALSE, options = list(searchHighlight = TRUE, pageLength = 20), filter = 'top') ``` About ======================================================================= **The Coronavirus Dashboard** Based in the project of RamiKrispin centered in Mexico by [Ricardo](https://github.com/rjof/coronavirus_dashboard_mexico) This Coronavirus dashboard provides an overview of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic. This dashboard is built with R using the Rmakrdown framework and can easily reproduce by others. The code behind the dashboard available [here](https://github.com/RamiKrispin/coronavirus_dashboard) **Data** The input data for this dashboard is the [coronavirus](https://github.com/RamiKrispin/coronavirus) R package (dev version). The data and dashboard is refreshed on a daily bases. The raw data pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus [repository](https://github.com/RamiKrispin/coronavirus-csv) **Packages** * Dashboard interface - the [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard/) package. * Visualization - the [plotly](https://plot.ly/r/) package for the plots and [leaflet](https://rstudio.github.io/leaflet/) for the map * Data manipulation - [dplyr](https://dplyr.tidyverse.org/), and [tidyr](https://tidyr.tidyverse.org/) * Tables - the [DT](https://rstudio.github.io/DT/) package **Deployment and reproducibly** The dashboard was deployed to Github docs. If you wish to deploy and/or modify the dashboard on your Github account, you can apply the following steps: * Fork the dashboard [repository](https://github.com/RamiKrispin/coronavirus_dashboard), or * Clone it and push it to your Github package * Here some general guidance about deployment of flexdashboard on Github page - [link](https://github.com/pbatey/flexdashboard-example) For any question or feedback, you can either open an [issue](https://github.com/RamiKrispin/coronavirus_dashboard/issues) or contact me on [Twitter](https://twitter.com/Rami_Krispin). **Contribution** The **Map** tab was contributed by [Art Steinmetz](@adababbage) on this [pull request](https://github.com/RamiKrispin/coronavirus_dashboard/pull/1). Thanks Art!